﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/smoothness/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.9.1.min.js"></script>		<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js"></script>																	<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->

<title>維護Squad所包含的主機</title>

<script type="text/javascript">

function selectSubSys() {
	
	$("input[type='checkbox']:first").prop("checked",false);	//把全選的勾去掉
	
	$("#subSysId").val( $("select#subsys option:selected").val() );
	
	$("#dOpt").remove();
	$("select#sqGroupId .forRemove").remove();
	
	/*	先查詢有那些群組集合 Select	*/
	var tmp ="";
	$("#fc").val("2");
	
	/*	將請選擇加入，以分辨都有選擇	*/
	tmp = "<option id='dOpt'>--請選擇--</option>";
	$("select#sqGroupId").append(tmp);
	
	
	$.post("QuerySqGroup",$("#a_form").serializeArray(),function(reses) {
		$.each(reses,function(i, res) {
			tmp = "<option class='forRemove' value='"+res.id+"'>"+res.name+" ("+res.id+")"+"</option>";
			$("select#sqGroupId").append(tmp);
		});
	});
	jQuery("#gd").clearGridData(true).jqGrid("setCaption","資源群組");
	
}

function selectSqGroup() {
	
	$("input[type='checkbox']:first").prop("checked",false);	//把全選的勾去掉
	
	$("#dOpt").remove();	//移去 --請選擇--
	var subSysName = $("#subsys option:selected").text();
	var sqGroupName = $("select#sqGroupId option:selected").text();
	
	jQuery("#gd").jqGrid('setGridParam',{
		url:"QuerySquad",
		datatype: "json",
		postData: {
			bssId: function() { return $("#bss option:selected").val(); },
			subSysId: function() { return $("#subsys option:selected").val(); },
			sqGroupId: function() { return $("select#sqGroupId option:selected").val(); },
			fc: function() { return "mappingSqGroupSquad"; }
		}
	}).jqGrid("setCaption",subSysName+" 子系統下 群組集合"+sqGroupName+" 所轄資源群組").trigger('reloadGrid');
	
	
	$("#gd").off('click',".jqgrow td input[type='checkbox']");
	$("#gd").on('click',".jqgrow td input[type='checkbox']", function () {
		$.post("ManipulateMpSquadSquadGroup",{ bssId:$("#bss option:selected").val(),subSysId:$("#subsys option:selected").val(),sqGroupId:$("select#sqGroupId option:selected").val(),squadId:$(this).parent().next().text(),currentUser:$.cookie("userId")},function(res) {
		});
	});
}

$(document).ready(function() {
	
	if ($.cookie("userId") == null) {
		
	} else {
		$("#a_form #loginUser").val( $.cookie("userId") );
		$("#a_form #isSU").val( $.cookie("isSU") );
		/*	先查詢有那些子系統供 Select	*/
		var tmp ="";
		$("#fc").val("mappingEnvSquad");
		$.post("QuerySubSys",$("#a_form").serializeArray(),function(reses) {
			$.each(reses,function(i, res) {
				tmp = "<option class='forRemove' value='"+res.id+"'>"+res.name+" ("+res.id+")"+"</option>";
				$("#subsys").append(tmp);
			});
		});
		
		$("#gd").jqGrid({
		   	colNames:["<input type='checkbox' onclick='checkBox(event)' />","資源群組ID", "資源群組名稱"],
		   	colModel:[
				{	/*	CheckBox for 勾選	*/
					name:'chkSqId',
					width:75,
					align:'center',
					edittype:"checkbox",
					formatter: "checkbox",
					sortable: false,
					formatoptions: {disabled:false}
				},
				{	/*	資源群組ID	*/
		   			name:"squadId",
		   			index:"squadId",
		   			editable:true,
		   			editrules:{
		   				required:true
		   			}
		   		},
		   		{	/*	資源群組名稱	*/
		   			name:"squadName",
		   			index:"squadName",
		   			editable:true,
		   			editrules:{
		   				required:true
		   				}
		   		}
		   	],
		   	rowNum: 6,
		   	pager: "#pager",
		   	forceFit: true,
			rownumbers: true,
		   	viewrecords: true,
		   	caption: "資源群組"
		});
		jQuery("#gd").jqGrid("navGrid","#pager",{add:false,edit:false,del:false,search:false,refresh:false});
		
		initPage("維護群組集合下轄資源群組");		
	}
}).tooltip();
</script>

</head>
<body>
<div id="header"></div>
	<p>
	<form id="q_form">
		<input type="hidden" id="bssId" name="bssId" />
		
		<input type="hidden" id="sqGroupId" name="sqGroupId" />
		
		<!-- 用來進行 Update時使用 -->
		<input type="hidden" id="oriHostIP" name="oriHostIP" />
		<input type="hidden" id="oriBssId" name="oriBssId" />
		<input type="hidden" id="oriSubSysId" name="oriSubSysId" />
		<input type="hidden" id="oriPort" name="oriPort" />
		<input type="hidden" id="hostName" name="hostName" />
		
	</form>
	<form id="a_form">
		<input type="hidden" id="fc" name="fc" />
		<input type="hidden" id="subSysId" name="subSysId" />
		<input type="hidden" id="loginUser" name="loginUser" />
		<input type="hidden" id="isSU" name="isSU" />
	</form>
	
	
	<br/>
	
<table>
<tr>
<th class="right"><label for="bss">系統：</label></th>
<td><select id="bss">
<option value="MBMS">MBMS</option>
</select></td>
</tr>
<tr>
<th class="right"><label for="subsys">子系統：</label></th>
<td>
	<select id="subsys" onchange="selectSubSys()"><option>--請選擇--</option></select>
</td>
</tr>
<tr>
<th class="right"><label for="sqGroupId">群組集合：</label></th>
<td>
	<select id="sqGroupId" onchange="selectSqGroup()" ><option id="dOpt">--請選擇--</option></select>
</td>
</tr>
</table>

<p>
<hr/>
<p>
<table id="gd"></table>
<div id="pager"></div>
<div id="kkk"></div>

</body>
</html>